<?php 
include './functions.php';
session_start();
$data = $_POST;
if(empty($data['addressee']) || empty($data['content'])){
	$error = true;
}else{
	
	$data['ctime']=time();
	$data['username']=$_SESSION['username'];
	$oldData = file_get_contents('./Db/db.json');
	$oldData = json_decode($oldData);
	$oldData[]=$data;
	$oldData=json_encode($oldData);
	file_put_contents('./Db/db.json', $oldData);
	header("Location:./index.php");
}

 ?>
<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script type="text/javascript">
		var  error = <?php echo $error; ?>;
		if(error){
			if(confirm("内容不能为空")){
				location.href = "./index.php";
			}
		}
	</script>
</head>
<body>
	
</body>
</html>